package edu.gatech.ors.mrsim.applicationtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.gatech.ors.mrsim.basictasks.NamedTask;
import edu.gatech.ors.mrsim.basictasks.WaitTask;
import edu.gatech.ors.mrsim.core.SimJob;
import edu.gatech.ors.mrsim.core.SimTask;
import edu.gatech.ors.mrsim.core.Simulator;
import edu.gatech.ors.mrsim.io.conf.Configuration;

public class Assignment2 {
    public static void main(String[] args){
	
	Configuration testConfig = new Configuration();
	
	//this isn't working for some strange reason
	//Andrey, your configuration class isn't working and I'm not quite sure why
	
	testConfig.setInt("numNodes",4);
	int numNodes = testConfig.getInt("numNodes");
	System.out.println("Num nodes is "+numNodes);
	
	
	//create a hdfs simulator using the default config and timer for assigment 2
	Simulator sim = new Simulator(new AS2Timer(),new AS2HDFS(testConfig));
	
	//run the simulation
	sim.simulate(new AS2TestJob());
    }
    
    public static class AS2Timer extends DefaultTimer {
	public long time(SimTask t){
	    
	    if (t instanceof NamedTask){
		NamedTask nt = (NamedTask) t;
		
	    }
	    if (t instanceof RequestFile){
		return 0;
	    }
	    
	    return super.time(t);
	}
    }
    
    public static class AS2TestJob implements SimJob {

	@Override
	public Map<String, List<SimTask>> getInitTasks() {
	    
	    Map<String, List<SimTask>> rv = new HashMap<String, List<SimTask>>();
	    
	    List<SimTask> requestTasks = new ArrayList<SimTask>();
	    //requestTasks.add(new WaitTask(10));
	    for (int i= 0;i<10;i++){
		    requestTasks.add(new RequestFile("file"+i));
	    }
	    rv.put("requestAgent",requestTasks);
	    
	    
	    return rv;
	}
	
	
	
	
	
    }
    
    public static class RequestFile extends SimTask {
	public String fileName;
	public RequestFile(String fileName){
	    this.fileName = fileName;
	}
	public String toString(){
	    return "RequestFile('"+fileName+"')";
	}
    }
}
